/*
 *  $Id: ManaThirst.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2009 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Air.Spells {
    public class ManaThirst: SelfEnchantmentCard {
        public ManaThirst(): base("001_a_s_mana_thirst") {
            Level = CompleteLevel.ReadyForTest;
            Version = 0;
            Element = ElementType.Air;
            Value = 100;
            AddManaCost(ElementType.Air, 1);
        }

        protected override EnchantmentAffect CreateEnchantment() {
            return new ManaThirstAffect();
        }

        private class ManaThirstAffect: EnchantmentAffect<ManaThirst> {
            private int _gainMana;

            public ManaThirstAffect() {}

            public override void SetAffect() {
                base.SetAffect();
                LocalSummary.OnStartOffencePhase += DoStart;
                LocalSummary.OnEndOffencePhase += DoEnd;
            }
            public override void ResetAffect() {
                base.ResetAffect();
                LocalSummary.OnStartOffencePhase -= DoStart;
                LocalSummary.OnEndOffencePhase -= DoEnd;
            }

            private void DoStart() {
                _gainMana = Owner.Owner.Meditation;
                Owner.Owner.IncrementMana(ElementType.Air, _gainMana);
            }
            private void DoEnd() {
                int currentMana = Owner.Owner.GetMana(ElementType.Air);
                if (_gainMana > 0 && currentMana >= _gainMana) {
                    Owner.Owner.DamageBy(NewDamage(DamageType.MagicAttack, currentMana));
                    Dispell();
                }
            }
        }
    }
}
